import { Controller, AppEvent } from "../../framework/framework";
import { ReptileModel } from '../models/model';
import { ReptileView } from '../views/view';

class ReptileController extends Controller implements IController {
    private _model: IModel;
    private _view: IView;

    constructor(metiator: IMediator) {
        super(metiator);
        this._model = new ReptileModel(metiator);
        this._view = new ReptileView(metiator);
    }

    // initialize views/ models and strat listening to controller actions
    public initialize(): void {
        // subscribe to controller action events
        this.subscribeToEvents([
            new AppEvent("app.controller.reptile.article_list", null, (e, symbol: string) => { this.article_list(symbol); })
        ]);

        // initialize view and models events
        this._model.initialize();
        this._view.initialize();
    }

    // dispose views/models and stop listening to controller actions
    public dispose(): void {

        // dispose the controller events
        this.unsubscribeToEvents();

        // dispose views and model events
        this._model.dispose();
        this._view.dispose();
    }

    public article_list(args: any) {
        this.triggerEvent(new AppEvent("app.model.reptile.article_list", args, null));
    }
}

export { ReptileController };
